define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	$scope.form.father_id=params.father_id;
	$scope.form.fk_grade=params.fk_grade;
	$scope.form.fk_unit=params.fk_unit;

	//查询学年
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_YEAR'},function(data){
		if("0000" === data.code){
			$scope.academics =  data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询学期
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_TERM'},function(data){
		if("0000" === data.code){
			$scope.semesters = data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询年级
	$scope.findGrade = function(){
		httpService.post(app.urls.grade_selectCenterGrade,{"fk_unit":$scope.form.fk_unit},function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	//获取班级
	$scope.findClass=function(){
		httpService.post(app.urls.class_selectClassName,{"fk_unit":$scope.form.fk_unit,"fk_grade":$scope.form.fk_grade,"status":'0'},function(data){
			if("0000" === data.code){
				$scope.classList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	//查询班级数据
	$scope.find = function(){
		$scope.form.list='list';
		httpService.postpage(app.urls.class_select,$scope.form,function(data){
			if("0000" === data.code){
    			$scope.rows = data.data;
    		}else{
    			alert(data.msg);
    		}
		});
	}

	$scope.findGrade($scope.form.fk_unit);
	$scope.findClass($scope.form.fk_unit,$scope.form.fk_grade);
	$scope.find();

	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	//执行查询班级数据
    	$scope.find();
    }
	//添加班主任
	$scope.addteacher = function(type,id,fk_unit){
	    eventBusService.publish("modal.page","modules/content/unitmanagement/class/addTeacher?FatherControllerName="+$scope.controllerName+"&id="+id+"&type="+type+"&fk_unit="+fk_unit);
	}

	//添加专业
	$scope.major = function(){

		var menu = {
			"url":"modules/content/recruitstudent/class/major/list?fk_menuid="+params.fk_menuid
		};

		eventBusService.publish("modules.content.load",menu);
	}

	//接收数据刷新
	eventBusService.subscribe('content.page.reload', function(event,data) {
		$scope.select();
		$scope.findClass($scope.form.fk_unit,$scope.form.fk_grade);
	});

	$scope.showul=function(num){
		$(".gzdw").removeClass("ss-display");
	}
	
	$scope.getSchool=function(school,num){
		if(school == 0){
			$scope.form.fk_unit = "";
			$scope.gzdwname = "";
			$(".gzdw").addClass("ss-display");
		}else{
			$scope.form.fk_unit = school.id;
			$scope.gzdwname = school.name;
			$(".gzdw").addClass("ss-display");
		}
		$scope.findGrade();
	}


	/**
	 * 添加学生
	 * @param row
	 */
	$scope.addStudent=function(row){
		console.log(row);
		eventBusService.publish("modal.page","modules/content/recruitstudent/class/addStudent?fk_class="+row.id+"&fk_major="+row.fk_major);
	}

	/**
	 * 下载模板
	 */
	$scope.downloadTemplate = function(){
		window.location.href = "assets/template/classStudent.xls";
	}

	/**
	 * 导入分班信息
	 */
	$scope.import = function(){
		eventBusService.publish("modal.page","modules/content/recruitstudent/class/import");
	}

		//选择数据
		$scope.optData = function (element) {
			if($(element).find("input[name='dataPk']").is(":checked")){
				$(element).find("input[name='dataPk']").prop("checked",false);
				$(element).removeClass("opt_tr");
			}else{
				$(element).find("input[name='dataPk']").prop("checked",true);
				$(element).addClass("opt_tr");
			}
		}
		$scope.checkAll = function(target) {
			$("#" + $scope.controllerName + " input[name='dataPk']").each(function() {
				if ($(this).prop("checked")) {
					$(this).prop('checked', false);
					$(this).parents("tr").removeClass("opt_tr");
				} else {
					$(this).prop('checked', true);
					$(this).parents("tr").addClass("opt_tr");
				}
			})
		}

	
}}});